package sctu.edu.java.year2016.team07.huangsuixin.day20160610.chapter12_2;

import java.io.*;

/**
 * Created by Huang Suixin on 2016/6/10.
 */
public class WriteAndRead {

    public void write(File file, String str) throws IOException {

        if (file.exists()) {
        } else {
            System.out.println("文件不存在！");
            return;
        }
        FileOutputStream fos = new FileOutputStream(file);
        FileWriter fw = new FileWriter(file);
        fw.write(str);
        fw.close();
    }

    public void read(File file) throws IOException {
        if (file.exists()) {
        } else {
            System.out.println("文件不存在");
            return;
        }
        FileReader fr = new FileReader(file);
        char[] c = new char[1024];
        fr.read(c);
        System.out.println(c);
        fr.close();
    }
}
